import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/practice_controller.dart';

class PracticePage extends StatelessWidget {
  PracticePage({super.key});

  final PracticeController controller = Get.put(PracticeController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('练习页面'),
      ),
      body: Column(
        children: [
          Obx(() => DropdownButton<String>(
                value: controller.selectedUnit.value,
                onChanged: (String? newValue) {
                  if (newValue != null) {
                    controller.selectedUnit.value = newValue;
                  }
                },
                items: ['第一单元', '第二单元', '第三单元']
                    .map<DropdownMenuItem<String>>((String value) {
                  return DropdownMenuItem<String>(
                    value: value,
                    child: Text(value),
                  );
                }).toList(),
              )),
          Expanded(
            child: Obx(() => ListView.builder(
                  itemCount: controller.words.length,
                  itemBuilder: (context, index) {
                    return ListTile(
                      title: Text(controller.words[index]),
                      onTap: () {
                        // TODO: 实现听写功能
                      },
                    );
                  },
                )),
          ),
        ],
      ),
    );
  }
}
